package com.yljk.yljkproject.ui;

import android.text.TextUtils;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.yilijk.base.constants.UserInfo;
import com.yilijk.base.utils.SharedPreferencesUtils;
import com.yljk.servicemanager.constants.ReactApi;
import com.yljk.servicemanager.constants.RouterApi;
import com.yljk.servicemanager.oldbase.ModuleBaseActivity;
import com.yljk.yljkproject.R;
import com.yljk.yljkproject.utils.ReactUtils;

@Route(path = RouterApi.CenterActivity)
public class CenterActivity extends ModuleBaseActivity {

    @Autowired
    public boolean isLogout = false;

    @Override
    protected void onRestart() {
        super.onRestart();
        String token = SharedPreferencesUtils.getInstance().getString(UserInfo.token, null);
        String mobile = SharedPreferencesUtils.getInstance().getString(UserInfo.mobile, null);
//        hasPassword = SharedPreferencesUtils.getInstance().getString(AllStringConstants.hasPassword, null);
//       if (token != null && mobile != null && mobile.length()==11 && hasPassword!=null && !hasPassword.equals("0")) {
//            ARouter.getInstance().build(RouterApi.MAIN_ACTIVITY).navigation();
//            finish();
//        }else if (token==null && mobile==null && hasPassword == null && !isLogout && !isLogin){
//            ReactUtils.INSTANCE.push(CenterActivity.this, ReactApi.LOGIN_DOCTORBUNDLE, ReactApi.Index);
//        } else{
//            finish();
//        }
        if (TextUtils.isEmpty(token) || TextUtils.isEmpty(mobile)){
            if (isLogout){
                ReactUtils.INSTANCE.push(this, ReactApi.LOGIN_DOCTORBUNDLE,ReactApi.Login.Index);
            }else{
                finish();
            }
        }else{
            ARouter.getInstance().build(RouterApi.MAIN_ACTIVITY).navigation();
        }
        finish();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
//        unregisterReceiver(broadcastReceiver);
    }

    @Override
    public int bondLayout() {
        return R.layout.activity_center;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        String token = SharedPreferencesUtils.getInstance().getString(UserInfo.token, null);
        String account_mobile = SharedPreferencesUtils.getInstance().getString(UserInfo.mobile, null);
        if (TextUtils.isEmpty(token) || TextUtils.isEmpty(account_mobile)){
            ReactUtils.INSTANCE.push(this, ReactApi.LOGIN_DOCTORBUNDLE,ReactApi.Login.Index);
            if (isLogout){
                isLogout = false;
            }
        }else{
            ARouter.getInstance().build(RouterApi.MAIN_ACTIVITY).navigation();
            finish();
        }
    }

    @Override
    public void initEvent() {

    }
}